﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace httphelper
{
    public class Util
    {
        /// <summary>
        /// 从流中读取数据，会先将流中字符串读取到文件，然后从文件中读取数据
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public static byte[] readBytes(Stream stream)
        {
            FileStream fs = new FileStream("temp", FileMode.Create);
            byte[] bs = new byte[1024];
            int len = 0;
            while ((len = stream.Read(bs, 0, bs.Length)) != 0)
            {
                fs.Write(bs, 0, len);
            }

            fs.Close();
            return FileUtil.ReadFile("temp");

        }
        /// <summary>
        /// 从流中读取字符串
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public static String readStrByStream(Stream stream)
        {
            StreamReader sr = new StreamReader(stream);
            return sr.ReadToEnd();

        }






    }
}
